<script setup>
import { reactive, ref } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
// ------------------------------用户搜索
const formInline = reactive({
    userId: '',
    vip: '',
    version: '',
    regst: 'all',
    reg: 'all',
    hot: 'all',
    dis: 'all',
    sup: 'all',
    dic: 'all',
    regTime: ''
})

const onSubmit = () => {
    console.log('submit!')
}
// ------------------------------用户数据
let users = reactive([
    {
        id: 40006, manager: '大飞', IP: '192.168.1.0', 
        object: '4051', content: '兰香子top1',
        handin: '2024-08-25 2:27:56',
    },
    {
        id: 40006, manager: '大飞', IP: '192.168.1.0', 
        object: '4051', content: '兰香子top1',
        handin: '2024-08-25 2:27:56',
    },
    {
        id: 40006, manager: '大飞', IP: '192.168.1.0', 
        object: '4051', content: '兰香子top1',
        handin: '2024-08-25 2:27:56',
    },
    {
        id: 40006, manager: '大飞', IP: '192.168.1.0', 
        object: '4051', content: '兰香子top1',
        handin: '2024-08-25 2:27:56',
    },
    {
        id: 40006, manager: '大飞', IP: '192.168.1.0', 
        object: '4051', content: '兰香子top1',
        handin: '2024-08-25 2:27:56',
    },
    {
        id: 40006, manager: '大飞', IP: '192.168.1.0', 
        object: '4051', content: '兰香子top1',
        handin: '2024-08-25 2:27:56',
    },
    {
        id: 40006, manager: '大飞', IP: '192.168.1.0', 
        object: '4051', content: '兰香子top1',
        handin: '2024-08-25 2:27:56',
    }
])

// ------------------------ 分页

const currentPage = ref(1)
const pageSize = ref(100)
const size = ref('default')
const background = ref(false)
const disabled = ref(false)

const handleSizeChange = (val) => {
  console.log(`${val} items per page`)
}
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`)
}

// ---------------------- 删除用户操作
// 弹出二次确认对话框：参数user就是要删除的用户：
function showConfirm(user) {
    ElMessageBox.confirm(
    '确定要删除id:' + user.id +'用户的信息吗?',
    '警告信息',
    {
      confirmButtonText: '确认',
      cancelButtonText: '取消',
      type: 'warning',
    }
  )
    .then(() => {
      // 调用删除函数：删除用户
      deleteUser(user)
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: '管理员取消了删除操作',
      })
    })
    
}

// 删除用户的函数：参数user就是要删除的用户
function deleteUser(user) {
    // 查询用户在数组中的索引
    let index = users.findIndex(item => item.id === user.id)
    // 删除用户数据
    users.splice(index, 1)
    // 提示删除成功
    ElMessage({
        type: 'success',
        message: '管理员成功删除了用户 ' + user.id,
      })
}


</script>
<template>


    <el-card>
        <el-form :inline="true" :model="formInline" class="demo-form-inline">
            <el-form-item label="时间">
                <el-date-picker
                    v-model="formInline.regTime"
                    type="daterange"
                    range-separator="To"
                    start-placeholder="开始时间"
                    end-placeholder="结束时间"
                />
            </el-form-item>
            <el-form-item label="关键字：">
                <el-input v-model="formInline.userId" placeholder="请输入会员ID、管理员ID" clearable />
            </el-form-item>
            <el-form-item>
                <el-button type="primary">搜索</el-button>
            </el-form-item>
            <el-form-item>
                <el-button type="success" >导出</el-button>
            </el-form-item>
        </el-form>
    </el-card>
    <el-table :data="users" style="width: 100%">
        <el-table-column label="ID" prop="id" width="80"/>
        <el-table-column label="管理员" prop="manager" width="80"/>
        <el-table-column label="IP" prop="IP" width="80"/>
        <el-table-column label="推送对象" prop="object" width="140"/>
        <el-table-column label=" 推送内容" prop="content" width="600"/>
        <el-table-column label="时间" prop="handin" width="180"/>
        <!-- {
        id: 40006, username: 'wx_17765007861', nickname: 'Eluck', avator: '', phone: '',
        balance: 50, cumCon: 0, ticket: 0.00, cumTicket: 0,
        invitation: '2CE0F8', regDevice: 'android',
        regTime: '2024-08-26 10:08:02',
        lastLogin: '2024-08-26 12:30:12',
        lastIp: '223.104.205.215',
        status: 0
    } -->
    </el-table>

    <el-pagination
      background
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :page-sizes="[100, 200, 300, 400]"
      :size="size"
      :disabled="disabled"
      :background="background"
      layout="total, sizes, prev, pager, next, jumper"
      :total="1000"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
</template>
<style scoped>
.demo-form-inline .el-input {
    --el-input-width: 220px;
}

.demo-form-inline .el-select {
    --el-select-width: 100px;
    font-size: 14px;
}

.demo-pagination-block + .demo-pagination-block {
  margin-top: 10px;
}
.demo-pagination-block .demonstration {
  margin-bottom: 16px;
}

.el-pagination{
    margin-top:20px;
}

.p-header{
    display:flex;
    justify-content: space-between;
}
</style>